home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-10-20 | 1.6 KB | 79 lines | [TEXT/CWIE] |
- // SecureCGrafPort.cp, the SecureCGrafPort class, useful for generating onscreen
- // CGrafPorts for those who do not use a framework to make CGrafPorts for them.
-
- // copyright © 1995, Macneil Shonle. All rights reserved.
-
- #ifndef __SECURECGRAFPORT__
- #include <SecureCGrafPort.h>
- #endif
-
- #ifndef __GWORLDSETTER__
- #include <GWorldSetter.h>
- #endif
-
- // constructs the CGrafPort to have drawings visible in the bounds argument
- // may throw: xalloc, invalidargument
- SecureCGrafPort::SecureCGrafPort(const Rect& bounds) throw(xalloc, invalidargument)
- : port(new CGrafPort)
- {
- if (port == 0)
- throw xalloc("new port failed", "SecureCGrafPtr::SecureCGrafPtr");
- ::OpenCPort(port);
-
- GWorldSetter setTo(port);
-
- Rect zeroBounds = bounds;
- ::OffsetRect(&zeroBounds, -zeroBounds.left, -zeroBounds.top);
-
- RgnHandle drawRegion = ::NewRgn();
- ::OpenRgn();
- ::FrameRect(&zeroBounds);
- ::CloseRgn(drawRegion);
-
- ::CopyRgn(drawRegion, port->visRgn);
- ::CopyRgn(drawRegion, port->clipRgn);
-
- ::PortSize(zeroBounds.right, zeroBounds.bottom);
- ::MovePortTo(bounds.left, bounds.top);
- }
-
- SecureCGrafPort::~SecureCGrafPort()
- {
- ::CloseCPort(port);
- delete port;
- }
-
- Rect& SecureCGrafPort::portRect() const
- {
- return port->portRect;
- }
-
- BitMapPtr SecureCGrafPort::bitMap() const
- {
- return &GrafPtr(port)->portBits;
- }
-
- short SecureCGrafPort::width() const
- {
- return port->portRect.right - port->portRect.left;
- }
-
- short SecureCGrafPort::height() const
- {
- return port->portRect.bottom - port->portRect.top;
- }
-
- CGrafPtr SecureCGrafPort::getMacPort() const
- {
- return port;
- }
-
- GDHandle SecureCGrafPort::getMacGD() const
- {
- return ::GetMainDevice();
- }
-
- SecureCGrafPort::operator CGrafPtr() const
- {
- return port;
- }